/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simulatefire.Building;

import java.util.InputMismatchException;
import java.util.Scanner;
import simulatefire.Building.RoomParts.RoomParts;

/**
 *
 * @author Nicolas
 * @version $Revision: 1.0 $
 */
public class Building {
    
    private int longeur = 0;
    private int largeur = 0;
    private int hauteur = 0;
    
    private RoomParts map[][][];
    
    
    /**
     * Constructor for Building.
     * @throws InterruptedException
     */
    public Building() throws InterruptedException {
    	
        Scanner keyboard = new Scanner(System.in);
        try{
            
            //get dimensions
                while(this.longeur<3){
                    System.out.println("Entrer la longueur du batiment");
                    this.longeur = keyboard.nextInt();
                }
                while(this.largeur<3){
                    System.out.println("Entrer la largeur du batiment");
                    this.largeur = keyboard.nextInt();
                }
                //seulement le premier etage pour le moment
                /*while(this.hauteur<3){
                    System.out.println("Entrer la hauteur du batiment");
                    this.hauteur = keyboard.nextInt();
                }*/
                this.hauteur = 1;

            //create Building
                this.map = new RoomParts[this.longeur][this.largeur][this.hauteur];
                initMap();
                
            //create rooms
                
            //Personalize Building
            
            //print building
                printBuilding();
                
        }catch(InputMismatchException e) {
            System.err.println("Wrong input, building creation aborted (error:" + e.getMessage() + ")");
        }
        
        /*finally{
        	keyboard.close();
        }*/
    }
    
    /**
     * Constructor for Building.
     * @param lo int
     * @param la int
     * @param ha int
     */
    public Building(int lo, int la, int ha) {
        
        this.longeur = lo;
        this.largeur = la;
        this.hauteur = ha;
            
        this.map = new RoomParts[lo][la][ha];
        initMap();
    }
    
    private void initMap(){
        for(int i=0; i < this.getLongeur(); i++){
            for(int j=0; j < this.getLargeur(); j++){
                for(int k=0; k < this.getHauteur(); k++){
                    this.map[i][j][k] = new RoomParts();
                }
            }
        }
    }
    
    /**
     * Method printBuilding.
     * @throws InterruptedException
     */
    public void printBuilding() throws InterruptedException{
        int k = 0; //seulement le premier étage pour le moment
        
        System.out.println("\nBuilding Map :");
        for(int i=0; i < this.getLongeur(); i++){
            for(int j=0; j < this.getLargeur(); j++){
                System.out.print( this.getMap()[i][j][k].getRoomPartsSymbol() );
            }
            System.out.println();
        }
        System.out.print("\n\n\n");
        Thread.sleep(1000);
    }
    
    /**
     * Method setFire.
     * @param x int
     * @param y int
     * @param z int
     */
    public void setFire(int x, int y, int z) {
        this.getMap()[x][y][z].setFire();
    }


    /**
    
     * @return the longeur */
    public int getLongeur() {
        return longeur;
    }

    /**
    
     * @return the largeur */
    public int getLargeur() {
        return largeur;
    }

    /**
    
     * @return the hauteur */
    public int getHauteur() {
        return hauteur;
    }

    /**
    
     * @return the map */
    public RoomParts[][][] getMap() {
        return map;
    }
    
}
